/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package mvc;

import java.rmi.Remote;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
 *
 * @author William
 */
public abstract class ControllerFactory implements Remote {
    private static Map<String, Controller> instances;
    private final String name;
    
    public ControllerFactory(String name) {
        this.name = name;
    }
    
    public abstract Controller getInstance();
    
    public static void registerNewInstance(Controller ctl) {
        ControllerFactory.instances.put(ctl.getName(), ctl);
    }
    
    public static void removeInstance(String name) {
        ControllerFactory.instances.remove(name);
    }
    
    public static Controller searchInstance(String name) {
        return ControllerFactory.instances.get(name);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 23 * hash + Objects.hashCode(this.name);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ControllerFactory other = (ControllerFactory) obj;
        if (!Objects.equals(this.name, other.name)) {
            return false;
        }
        return true;
    }
    
    
}
